package com.shop.utils;

import org.jasypt.encryption.pbe.PooledPBEStringEncryptor;
import org.jasypt.encryption.pbe.StandardPBEByteEncryptor;
import org.jasypt.encryption.pbe.config.SimpleStringPBEConfig;

/**
 * 加密类
 */
public class JasyptUtils {

    public static PooledPBEStringEncryptor encryptOr ;
    public static SimpleStringPBEConfig config;

    static {
        encryptOr = new PooledPBEStringEncryptor();
        config = new SimpleStringPBEConfig();
        config.setPassword("dawn");
        config.setAlgorithm(StandardPBEByteEncryptor.DEFAULT_ALGORITHM);
        config.setKeyObtentionIterations("1000");
        config.setPoolSize("1");
        config.setProviderName(null);
        config.setSaltGeneratorClassName("org.jasypt.salt.RandomSaltGenerator");
        config.setStringOutputType("base64");
        encryptOr.setConfig(config);
    }

    /**
     * Jasypt生成加密结果
     *
     * @param value 待加密值
     * @return
     */
    public static String encryptPwd(String value) {
        return encryptOr.encrypt(value);
    }

    /**
     * 解密
     *
     * @param value 待解密密文
     * @return
     */
    public static String decryptPwd(String value) {
        return encryptOr.decrypt(value);
    }
}
